<template>
    <div class="zydd-wrapper">
        <div class="zydd-wrapper-loader">
        </div>
        <p>登陆跳转中</p>
    </div>
</template>

<script setup lang="ts">

import { onMounted } from 'vue'
import dd from 'gdt-jsapi'
import {  path } from '@/utils'

const local = window.location.href.split('?')


let state: string = ''
if (local[1]?.includes('#')) {
	state = local[1].split('=')[1].split('#')[0]
} else {
	state = local[1]?.split('=')[1] ?? ''
}

onMounted(() => {
    // 获取 专有钉钉 code
    dd.getAuthCode({}).then(res =>{
        dd.getLoginUser().then(result => {
            result.accountId && localStorage.setItem('accountId', result.accountId)
        })
        if (res) {
            if(res.code) {
                window.location.href = path.getFullPath(`/ego_base_info/v1/public/sso/zydd/login?auth_code=${res.code}&state=${state}`)
            } else {
                window.location.href =  path.getFullPath(`/ego_base_info/v1/public/sso/zydd/login?auth_code=${res.auth_code}&state=${state}`)
            }
        }
    })
})
</script>

<style lang='less' scoped>
.zydd-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    flex-direction: column;
    background: #fff;
    .zydd-wrapper-loader {
        border: 4px solid #f3f3f3;
        border-radius: 50%;
        border-top: 4px solid #3498db;
        width: 45px;
        height: 45px;
        -webkit-animation: spin 2s linear infinite;
        animation: spin 2s linear infinite;
    }

    @-webkit-keyframes spin {
        0% { -webkit-transform: rotate(0deg); }
        100% { -webkit-transform: rotate(360deg); }
    }

    @keyframes spin {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
    }

    p {
        margin-top: 20px;
        color:#3498db;
    }
}

</style>